<extend name="admin/main"/>

<block name="title">
    <title>产品列表</title>
</block>

<block name="css"></block>

<block name="heading">产品列表</block>

<block name="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form" method="get">
                <div class="form-group">
                    <div class="col-md-4">
                        <input type="text" id="search" name="search" value="{$search}" class="form-control">
                    </div>
                    <button class="btn btn-success">搜索</button>
                </div>
            </form>
            <table class="table table-bordered table-hover text-center">
                <thead>
                <tr>
                    <th class="text-center text-uppercase">#</th>
                    <th class="text-center text-uppercase">分类</th>
                    <th class="text-center text-uppercase">title</th>
                    <th class="text-center text-uppercase">icon</th>
                    <th class="text-center text-uppercase">description</th>
                    <th class="text-center text-uppercase">banner</th>
                    <th class="text-center text-uppercase">updated_at</th>
                    <th class="text-center text-uppercase">created_at</th>
                    <th class="text-center text-uppercase">action</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="data" item="product">
                    <tr data-id="{$product.id}">
                        <td>{$product.id}</td>
                        <td>{$product.category}</td>
                        <td>{$product.title}</td>
                        <td><img src="{$product.icon}" height="30"></td>
                        <td>{$product.description}</td>
                        <td><img src="{$product.banner}" height="30"></td>
                        <td>{$product.updated_at}</td>
                        <td>{$product.created_at}</td>
                        <td>
                            <div class="btn-group">
                                <a href="/home/pro_details?id={$product.id}" target="_blank"
                                   class="btn btn-info-alt btn-sm"><i class="ti ti-info"></i>
                                </a>
                                <a href="/admin/product/edit?id={$product.id}" class="btn btn-indigo-alt btn-sm">
                                    <i class="fa fa-edit"></i>
                                </a>
                                <a class="btn btn-warning-alt btn-sm delete-product">
                                    <i class="ti ti-trash"></i>
                                </a>
                            </div>
                        </td>
                    </tr>
                </foreach>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="9" class="text-left">
                        {$products->link(['search' => $search])}
                    </td>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</block>

<block name="js">
    <script type="text/javascript" src="__PUBLIC__/assets/demo/demo.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/demo/demo-switcher.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/plugins/bootbox/bootbox.js"></script>
    <script>
        $(document).ready(function () {
            $('.delete-product').click(function () {
                var id = $(this).parents('tr').attr('data-id');
                bootbox.confirm('是否删除?', function (r) {
                    if (r === false) return;
                    $.post('/admin/product/delete', {id: id}, function (res) {
                        var data = JSON.parse(res);
                        if (data.success === false) {
                            new PNotify({
                                title: 'Oh On!',
                                text: JSON.stringify(data.data),
                                type: 'error',
                                icon: 'ti ti-info-alt',
                                styling: 'fontawesome'
                            });
                        } else {
                            window.location.reload();
                        }
                    });
                });
            });
        });
    </script>
</block>
